package com.mall.db.api;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.mapper.SmsCouponHistoryMapper;
import com.mall.domain.SmsCouponHistory;
import com.mall.interface1.api.SmsCouponHistoryApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsCouponHistoryApiImpl implements SmsCouponHistoryApi {

    @Autowired
    private SmsCouponHistoryMapper smsCouponHistoryMapper;

    //返回领取记录
    public List<SmsCouponHistory> list(Long couponId, String orderSn, Integer pageNum, Integer pageSize, Integer useStatus) {
        Page<SmsCouponHistory> historyPage = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsCouponHistory>  queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(couponId != null,SmsCouponHistory::getCouponId,couponId);
        queryWrapper.eq(StrUtil.isNotEmpty(orderSn),SmsCouponHistory::getOrderSn,orderSn);
        queryWrapper.eq(useStatus != null,SmsCouponHistory::getUseStatus,useStatus);
        Page<SmsCouponHistory> hPage = smsCouponHistoryMapper.selectPage(historyPage, queryWrapper);
        return hPage.getRecords();
    }

    //返回领取记录总数
    public Integer count(Long couponId, String orderSn, Integer pageNum, Integer pageSize, Integer useStatus) {
        LambdaQueryWrapper<SmsCouponHistory>  queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(couponId != null,SmsCouponHistory::getCouponId,couponId);
        queryWrapper.eq(StrUtil.isNotEmpty(orderSn),SmsCouponHistory::getOrderSn,orderSn);
        queryWrapper.eq(useStatus != null,SmsCouponHistory::getUseStatus,useStatus);
        return smsCouponHistoryMapper.selectCount(queryWrapper);
    }
}
